//
//  HNSH_RewardPoolViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/3.
//

#import "HNSH_RewardPoolViewController.h"

//view
#import "HNSH_RewardPoolCell.h"

@interface HNSH_RewardPoolViewController ()

/**  */
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
/**  */
@property (nonatomic, strong)NSMutableArray * dataArray;
/**  */
@property (nonatomic, assign)NSInteger page;

@end

static NSString *HNSH_RewardPoolCellID = @"HNSH_RewardPoolCellID";

@implementation HNSH_RewardPoolViewController

//MARK: Cycle Methods
- (void)viewDidLoad{
    [super viewDidLoad];
    
    [self configTableView];
}

- (void)configTableView {
    [self setupRefresh:self.tableView option:ST_RefreshDefault];
    [self setupEmpty:self.tableView image:[UIImage imageNamed:@"empty_list_data"] title:@""];
    
    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    self.tableView.rowHeight = 60;
    [self.tableView registerClass:[HNSH_RewardPoolCell class] forCellReuseIdentifier:HNSH_RewardPoolCellID];
}


#pragma mark networking
- (void)refreshData:(NSInteger)page {
    [HNSH_UserNetServer requestBillListWithParams:@{} success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            [self.dataArray removeAllObjects];
            NSArray * records = responseObject.resultset[@"list"];
            NSArray * array = [NSArray yy_modelArrayWithClass:HNSH_RewardPoolModel.class json:records];
            [self.dataArray addObjectsFromArray:array];
            [self endRefresh:array.count>=10];
            [self.tableView reloadData];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataArray;
}

//MARK: UITableViewDelegate Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSLog(@"self.dataArray.count ==> %ld",self.dataArray.count);
    return 10;
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HNSH_RewardPoolCell * cell = [tableView dequeueReusableCellWithIdentifier:HNSH_RewardPoolCellID];
//    cell.model = self.dataArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    !self.scrollCallback ?: self.scrollCallback(scrollView);
}

//MARK: JXPagingViewListViewDelegate Methods
- (UIView *)listView{
    return self.view;
}

- (UIScrollView *)listScrollView{
    return self.tableView;
}

- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback{
    self.scrollCallback = callback;
}

- (void)listWillAppear{
    NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
}

- (void)listDidAppear{
    NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
}

- (void)listWillDisappear{
    NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
}

- (void)listDidDisappear{
    NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
}

@end
